home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch1 / Scroll.frm (.txt) < prev    next >
Visual Basic Form  |  1999-04-16  |  4KB  |  131 lines

  1. VERSION 5.00
  2. Begin VB.Form frmScroll 
  3.    Caption         =   "Scroll"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.HScrollBar hbarMarble 
  13.       Height          =   255
  14.       Left            =   0
  15.       TabIndex        =   3
  16.       Top             =   2400
  17.       Width           =   2295
  18.    End
  19.    Begin VB.VScrollBar vbarMarble 
  20.       Height          =   2295
  21.       Left            =   2400
  22.       TabIndex        =   2
  23.       Top             =   0
  24.       Width           =   255
  25.    End
  26.    Begin VB.PictureBox picOuter 
  27.       Height          =   2295
  28.       Left            =   0
  29.       ScaleHeight     =   2235
  30.       ScaleWidth      =   2235
  31.       TabIndex        =   0
  32.       Top             =   0
  33.       Width           =   2295
  34.       Begin VB.PictureBox picInner 
  35.          AutoSize        =   -1  'True
  36.          BorderStyle     =   0  'None
  37.          Height          =   6045
  38.          Left            =   360
  39.          Picture         =   "Scroll.frx":0000
  40.          ScaleHeight     =   6045
  41.          ScaleWidth      =   6225
  42.          TabIndex        =   1
  43.          Top             =   240
  44.          Width           =   6225
  45.       End
  46.    End
  47. Attribute VB_Name = "frmScroll"
  48. Attribute VB_GlobalNameSpace = False
  49. Attribute VB_Creatable = False
  50. Attribute VB_PredeclaredId = True
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53. ' Arrange the scroll bars.
  54. Private Sub ArrangeControls()
  55. Dim border_width As Single
  56. Dim got_wid As Single
  57. Dim got_hgt As Single
  58. Dim need_wid As Single
  59. Dim need_hgt As Single
  60. Dim need_hbar As Boolean
  61. Dim need_vbar As Boolean
  62.     ' See how much room we have and need.
  63.     border_width = picOuter.Width - picOuter.ScaleWidth
  64.     got_wid = ScaleWidth - border_width
  65.     got_hgt = ScaleHeight - border_width
  66.     need_wid = picInner.Width
  67.     need_hgt = picInner.Height
  68.     ' See if we need the horizontal scroll bar.
  69.     If need_wid > got_wid Then
  70.         need_hbar = True
  71.         got_hgt = got_hgt - hbarMarble.Height
  72.     End If
  73.     ' See if we need the vertical scroll bar.
  74.     If need_hgt > got_hgt Then
  75.         need_vbar = True
  76.         got_wid = got_wid - vbarMarble.Width
  77.         ' See if we now need the horizontal scroll bar.
  78.         If (Not need_hbar) And need_wid > got_wid Then
  79.             need_hbar = True
  80.             got_hgt = got_hgt - hbarMarble.Height
  81.         End If
  82.     End If
  83.     ' Arrange the controls.
  84.     picOuter.Move 0, 0, got_wid + border_width, got_hgt + border_width
  85.     If need_hbar Then
  86.         hbarMarble.Move 0, got_hgt + border_width, got_wid + border_width
  87.         hbarMarble.Min = 0
  88.         hbarMarble.Max = picInner.ScaleWidth - got_wid
  89.         hbarMarble.SmallChange = got_wid / 5
  90.         hbarMarble.LargeChange = got_wid
  91.         hbarMarble.Visible = True
  92.     Else
  93.         hbarMarble.Value = 0
  94.         hbarMarble.Visible = False
  95.     End If
  96.     If need_vbar Then
  97.         vbarMarble.Move got_wid + border_width, 0, vbarMarble.Width, got_hgt + border_width
  98.         vbarMarble.Min = 0
  99.         vbarMarble.Max = picInner.ScaleHeight - got_hgt
  100.         vbarMarble.SmallChange = got_hgt / 5
  101.         vbarMarble.LargeChange = got_hgt
  102.         vbarMarble.Visible = True
  103.     Else
  104.         vbarMarble.Value = 0
  105.         vbarMarble.Visible = False
  106.     End If
  107. End Sub
  108. Private Sub Form_Load()
  109.     picInner.AutoSize = True
  110.     picInner.Move 0, 0
  111. End Sub
  112. Private Sub Form_Resize()
  113.     ArrangeControls
  114. End Sub
  115. ' Reposition picInner.
  116. Private Sub hbarMarble_Change()
  117.     picInner.Left = -hbarMarble.Value
  118. End Sub
  119. ' Reposition picInner.
  120. Private Sub hbarMarble_Scroll()
  121.     picInner.Left = -hbarMarble.Value
  122. End Sub
  123. ' Reposition picInner.
  124. Private Sub vbarMarble_Change()
  125.     picInner.Top = -vbarMarble.Value
  126. End Sub
  127. ' Reposition picInner.
  128. Private Sub vbarMarble_Scroll()
  129.     picInner.Top = -vbarMarble.Value
  130. End Sub
  131.